import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/pages/community/community.dart';
import 'package:flutter_app/pages/home/index.dart';
import 'package:flutter_app/pages/house_details/index.dart';
import 'package:flutter_app/pages/house_management/index.dart';
import 'package:flutter_app/pages/house_recommend/house_recommend.dart';
import 'package:flutter_app/pages/information/index.dart';
import 'package:flutter_app/pages/login.dart';
import 'package:flutter_app/pages/my_collection/my_collection.dart';
import 'package:flutter_app/pages/not_found.dart';
import 'package:flutter_app/pages/register.dart';
import 'package:flutter_app/pages/release_house/index.dart';
import 'package:flutter_app/pages/setting/index.dart';

class Routes {
  // 定义路由的名字
  static String home = '/';
  static String login = '/login';
  static String register = '/register';
  static String setting = '/setting';
  static String houseManagement = '/houseManagement';
  static String houseRecommend = '/houseRecommend';
  static String releaseHouse = '/releaseHouse';
  static String houseDetail = '/houseDetail/:roomId';
  static String latestInfo = '/latestInfo';
  static String myCollection = '/myCollection';
  static String selectCommunity = '/selectCommunity';

/* 定义路由处理函数 */
  static Handler homeHandler = Handler(handlerFunc: (context, params) {
    return const HomePage();
  });

  static Handler loginHandler = Handler(handlerFunc: (context, params) {
    return const LoginPage();
  });

  static Handler registerHandler = Handler(handlerFunc: (context, params) {
    return const RegisterPage();
  });

  static Handler settingHandler = Handler(handlerFunc: (context, params) {
    return const SettingPage();
  });

  static Handler houseManagementHandler =
      Handler(handlerFunc: (context, params) {
    return HouseManagement();
  });

  static Handler houseRecommendHandler =
      Handler(handlerFunc: (context, params) {
    return const HouseRecommendPage();
  });

  static Handler releaseHouseHandler = Handler(handlerFunc: (context, params) {
    return const ReleaseHousePage();
  });

  static Handler latestInfoHandler = Handler(handlerFunc: (context, params) {
    return const Informationpage();
  });

  static Handler myCollectionHandler = Handler(handlerFunc: (context, params) {
    return const MyCollectionPage();
  });

  static Handler houseDetailHandler = Handler(handlerFunc: (context, params) {
    return HouseDetailPage(
      roomId: params['roomId']![0],
    );
  });

  static Handler selectCommunityHandler =
      Handler(handlerFunc: (context, params) {
    return CommunityPage();
  });

  /// @description: 关联路由名称和处理函数
  /// @param {*} router
  static void configureRoutes(FluroRouter router) {
    // 无法匹配路由时的处理
    router.notFoundHandler = Handler(handlerFunc: (context, params) {
      debugPrint('Route not found.');
      return const NotFoundPage();
    });

    router.define(home, handler: homeHandler);
    router.define(login, handler: loginHandler);
    router.define(register, handler: registerHandler);
    router.define(setting, handler: settingHandler);
    router.define(houseManagement, handler: houseManagementHandler);
    router.define(releaseHouse, handler: releaseHouseHandler);
    router.define(houseDetail, handler: houseDetailHandler);
    router.define(houseRecommend, handler: houseRecommendHandler);
    router.define(latestInfo, handler: latestInfoHandler);
    router.define(myCollection, handler: myCollectionHandler);
    router.define(selectCommunity, handler: selectCommunityHandler);
  }
}
